/**
 * [41] 缺失的第一个正数
 *
 * @format
 * @lc app=leetcode.cn id=41 lang=javascript
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var firstMissingPositive = function (nums) {
    let miss = 1
    const appeared = {}
    for (let i = 0; i < nums.length; i++) {
        if (nums[i] > 0) appeared[nums[i]] = true
    }
    while (true) {
        if (appeared[miss]) miss++
        else break
    }
    return miss
}
// var firstMissingPositive = function (nums) {
//     nums.sort((a, b) => a - b)
//     let [i, miss] = [0, 1]
//     while (i < nums.length) {
//         if (miss > nums[i]) i++
//         else if (miss == nums[i]) miss++, i++
//         else break
//     }
//     return miss
// }
// @lc code=end
